package managers.strategy;

import java.util.Enumeration;
import java.util.Random;

import managers.ElevatorManager;

import state.group.GroupDispatcherState;
import state.group.HallCall;

public class RandomStrategy extends HallCallStrategy {
    
    private Random r;
    
    public RandomStrategy()
    {
        r = new Random();
    }

    @Override
    public Byte assignHallCall(HallCall call)
    {
        GroupDispatcherState state = ElevatorManager.getInstance().getDispatcherState();
        
        Byte assignedElevator = 0;
        
        synchronized(state.elevatorData)
        {
            int maxNum = state.elevatorData.size();
            
            if (maxNum == 0)
            {
                return 0;
            }
            
            int assignedNo = r.nextInt(maxNum);
            
            Enumeration<Byte> e = state.elevatorData.keys();
            
            for (int i = 0;i <= assignedNo;i++)
            {
                assignedElevator = e.nextElement();
            }
        }
        
        return assignedElevator;
    }

    @Override
    public void resolveHallCall(HallCall call)
    {
        // NOOP
    }

    @Override
    public void verifyHallCalls()
    {
        // NOOP
    }
    
}
